//Contains declaration to all the global variables//

#include "projectHeader.h"

// Declared in sv_node.cc
bool resetOptionDetected=false;
char * configFileName=NULL;	


// Used in initParse.cc
uint16_t port=0;
int autoShutDown=900;
int msgLifeTime=30;
int ttl=30;
int minNeighbour=2;
int keepAliveTimeOut=60;
int initNeighbour=3;
float neighbourStoreProb=0.2;
float cacheProb=0.1;
int cacheSize=500;
int cacheSizeInBytes=500*1024;
int remainingCacheSizeInBytes=500*1024;
bool cntrlCFlag=false;
float storeProb=0.1;
int noCheck=0;
int joinTimeOut=15;
int getMsgLifeTime=300;
uint32_t  location=0;
int retry=30;
char *logFileName;
char homeDir[512];
char statusFileName[512];
char storeFileName[512];
uint32_t statusInputTTL=0;
uint32_t storeInputTTL=0;
bool allowGet=false;
FILE* logFilePtr;
sigset_t set;          
bool logAlreadyOpen=false;
struct sigaction action; 
struct timeval tv;
bool getFileNameSpcified=false;
bool portFlag=false;
bool retryFlag=false;
bool locFlag=false;
bool homedirFlag=false;
bool logFileFlag=false;
bool ttlFlag=false;
bool msgLifeTimeFlag=false;
bool minNeighbourFlag=false;
bool autoshutFlag=false;
bool getMsgLifeTimeFlag=false;
bool joinTimeOutFlag=false;
bool storeProbFlag=false;
bool keepAliveTimeoutFlag=false;
bool cacheProbFlag=false;
bool cacheSizeFlag=false;
bool noCheckFlag=false;
bool neighborStoreProbFlag=false;
bool initNeighbourFlag=false;
list<hostPort> beaconList;
list<hostPort> nonBeaconList;
char myHostName[512];
bool iAmBeacon=false;
time_t inittime;
hostPort myHostPortInfo;
unsigned char buf[SHA_DIGEST_LENGTH];
char* nodeInstanceId=(char*)malloc(512*sizeof(char));
int listenqueue = 15;
int checkMsg=1;

bool softRestartFlag = false;
bool broadCastSent = false; 
char errorCode='0';
bool checkFlagReceived=false;

FILE* initNeighbourListFP;
FILE *namFilePtr;

bool fileOpenSucces=false;
volatile bool joinTimeOutBool=false;

map<string,int> connectedNodeList;
multimap<int,hostPort> joinDistList;
map<int,int> sockFDToQIndexMap ;//(sockfd,bitmapindex)
map<int,int> keepAliveTimers;   //(index,keepalivetimer)
map<int,list<int> > statusRespMap;
bitset<512> wQueueIndexBitMap;
list<queueItem> eventQueue;
list<queueItem> wrtieThreadQueue[512];
map<string,msgLifeTimeClass> UOIDMsgLifeTimeMap;

char userInput[512];
bool terminate=false;
int joinTimeOutSockFd=-1;

//=======pThread variables needed for beacon accept and connect========//
pthread_t *connectingThread;
pthread_t acceptingThread;
pthread_mutex_t printMutex;
pthread_mutex_t UOIDMsgLifeTimeMapMutex;
pthread_mutex_t joinTimeOutBoolMutex;
pthread_mutex_t connectedNodeListMutex;
pthread_t nonBeaconJoinConnectThread;
pthread_t nonBeaconJoinTimeOut;
pthread_t eventDispatcherThreadId;
pthread_mutex_t wQBitsetMutex;
pthread_mutex_t sockIndexMapMutex;
pthread_t msgLifeTimer;
pthread_mutex_t eventQueueMutex;
pthread_cond_t eventQueueCV;
pthread_mutex_t wrtieQMutex[512];
pthread_cond_t wrtieQCV[512];
pthread_t keepAlive;        
pthread_t keepAliveTimeout; 
pthread_mutex_t keepAliveMapMutex;
pthread_t userTermialThread;
pthread_t checkTimeOut;
pthread_mutex_t logFileMutex;
pthread_mutex_t cntrlCFlagMutex;
pthread_mutex_t checkTimeoutMutex;
pthread_cond_t checkTimeoutCV;


pthread_mutex_t readWriteMutex;
int acceptCounter=0;
pthread_t readBeacon[512];
pthread_t writeBeacon[512];



//=======================================================================

list<string> storeKeywordsList;

list<bitVectorIndexItem> indexBitVectoreList;
multimap<string,int> indexSHA1Map;
map<int,string> numToFileIdMap;
list<indexFileMetaInfo> indexFileMetaInfoList;
pthread_mutex_t indexMutex;
pthread_mutex_t tempfileindexlock;
pthread_mutex_t statusFileWriteLock;
int numFileNameCounter=1;
int tempFileIndex=1;
int lastStatusType=0;
int getFileNumber=0;
char getFileName[512];

map<int,searchResponseInfo> indexSearchResponseMap;
int searchIndex=1;

char delNonce[41];     
char delSHA1[41];      
char delFileName[512]; 
